// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::path::PathBuf;
use std::fs::read_dir;

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
async fn get_images(path: String) -> Vec<String> {
    let path = PathBuf::from(path);

    let images:Vec<String> = read_dir(path)
        .unwrap()
        .filter_map(|entry| entry.ok())
        .filter(|entry| entry.path().extension().map_or(
            false,
            |ext| {
                ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "webp" || ext == "mp4"
            }
        ))
        .map(|entry| entry.path().to_str().unwrap().to_string())
        .collect();
    
    images
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![get_images])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
